<?php
/**
 * 手机适配 使用WURFL适配手机型号 WURFL版本号为1.44
 * 
 * @name				
 * @package				
 * @file                $RCSfile:$
 * @version				$Revision:$
 * @modifiedby			$Author:$
 * @lastmodified		$Date:$
 */
class Lib_Wurfl
{
    /**
     * 手机详细信息
     * */
    private $requestingDevice;
    /**
     * wurfl object
     * */
    private $wurflManager;
    /**
     * 构造函数
     * 
     * */
    function __construct(){
        $wurflDir = dirname(__FILE__)."/WURFL";
        $resourcesDir = dirname(__FILE__)."/WURFL/resources";
        require_once $wurflDir.'/Application.php';
        $wurflConfigFile = $resourcesDir.'/wurfl-config.xml';
        // Create WURFL Configuration from an XML config file
        $wurflConfig = new WURFL_Configuration_XmlConfig($wurflConfigFile);
        // Create a WURFL Manager Factory from the WURFL Configuration
        $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);
        // Create a WURFL Manager
        /* @var $wurflManager WURFL_WURFLManager */
        $this->wurflManager = $wurflManagerFactory->create();
        //        $wurflInfo = $wurflManager->getWURFLInfo();
//        $this->requestingDevice = $wurflManager->getDeviceForHttpRequest($_SERVER);
        //        print_z($requestingDevice);
    }
    
    function getDeviceForUserAgent($UA){
        if(empty($UA)) return false;
        $this->requestingDevice = $this->wurflManager->getDeviceForUserAgent($UA);
    }
    
    function getDeviceForHttpRequest($UA){
        $this->requestingDevice = $this->wurflManager->getDeviceForHttpRequest($_SERVER);
    }
    
    function get_preferred_markup(){
        return $this->requestingDevice->getCapability('preferred_markup');
    }
    function get_wml_1_2(){
        return $this->requestingDevice->getCapability('wml_1_2');
    }
    function get_ajax_info(){
        $info['ajax_manipulate_css'] = $this->requestingDevice->getCapability('ajax_manipulate_css');
        $info['ajax_manipulate_dom'] = $this->requestingDevice->getCapability('ajax_manipulate_dom');
        $info['ajax_support_event_listener'] = $this->requestingDevice->getCapability('ajax_support_event_listener');
        $info['ajax_support_events'] = $this->requestingDevice->getCapability('ajax_support_events');
        $info['ajax_support_getelementbyid'] = $this->requestingDevice->getCapability('ajax_support_getelementbyid');
        $info['ajax_support_inner_html'] = $this->requestingDevice->getCapability('ajax_support_inner_html');
        $info['ajax_support_javascript'] = $this->requestingDevice->getCapability('ajax_support_javascript');
        $info['css_rounded_corners'] = $this->requestingDevice->getCapability('css_rounded_corners');
        return $info;
    }
}

